<template>
  <view>
    <uni-popup ref="toastPopup" type="center" :is-mask-click="isMaskClick" @maskClick="onMaskClick">
      <view class="toast-box">
        <view class="toast-header-box">
          <view class="text-center">
            <text class="text-black text-xxl text-bold">{{ title }}</text>
          </view>
          <view class="text-left content-box">
            <view v-for="(item, index) in contentList" :key="index">
              <text class="text-gray-df text-xl">{{ item }}</text>
            </view>
          </view>
        </view>
        <view :class="{'row': showCancel}">
          <view v-if="showCancel" class="col col-6">
            <view class="btn" :class="{'btn-cancel': showCancel}" @tap="onMaskClick">
              <text class="text-black text-bold">取消</text>
            </view>
          </view>
          <view :class="{'col col-6': showCancel}">
            <view class="btn" :style="{'width': showCancel ? '40vw' : '80vw'}" @tap="onOk">
              <text class="text-blue-btn text-bold">确定</text>
            </view>
          </view>
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
  export default {
    name: "toast-modal",
    props: {
      isShow: {
        type: Boolean,
        default: false
      },
      isMaskClick: {
        type: Boolean,
        required: false,
        default: true
      },
      title: {
        type: String,
        required: false,
        default: '提示'
      },
      content: {
        type: String,
        required: false,
        default: ''
      },
      align: {
        type: String,
        required: false,
        default: 'left'
      },
      showCancel: {
        type: Boolean,
        required: false,
        default: true
      },
    },
    data() {
      return {
        contentList: [],
      };
    },
    watch: {
      isShow: {
        handler(val) {
          if (val) {
            this.openPopup();
          } else {
            this.closePopup();
          }
        },
        deep: true
      },
      content: {
        handler(val) {
          this.contentList = !util.judgeNull(val) ? val.split("+") : [];
        },
        deep: true
      },
    },
    methods: {
      openPopup() {
        this.$refs.toastPopup.open();
      },
      closePopup() {
        this.$refs.toastPopup.close();
      },

      onMaskClick() {
        this.$emit('mask', false);
      },

      onOk() {
        this.$emit('ok');
        this.onMaskClick();
      }
    },
  }
</script>

<style lang="scss" scoped>
  @import "@/scss/common.scss";

  .toast-box {
    width: 80vw;
    flex: 1;
    border-radius: 20rpx;
    background-color: #ffffff;
  }

  .toast-header-box {
    padding: 50rpx 50rpx 0 50rpx;
    border-bottom: 1px solid #efefef;
  }

  .content-box {
    margin: 30rpx 0 50rpx 0;
    line-height: 1.5;
  }

  .btn {
    height: 7vh;
    font-size: 34upx;
    text-align: center;
    line-height: 50px;
  }

  .btn-cancel {
    width: 40vw;
    border-right: 1px solid #efefef;
  }
</style>
